 

package com.zdkj.subway.rca.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.rca.dto.in.SwCkConfiirmProcessItvmEpaymentNewDTO;
import com.zdkj.subway.rca.entity.SwCkConfiirmProcessItvmEpayment;
import com.zdkj.subway.rca.service.SwCkConfiirmProcessItvmEpaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * 对账确认过程-ITVM支付表
 *
 * @author stw
 * @date 2020-10-26 15:13:52
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckconfiirmprocessitvmepayment" )
@Api(value = "swckconfiirmprocessitvmepayment", tags = "银行票据单管理-银行电子账单与对账确认表-对账确认过程-ITVM支付表管理")
public class SwCkConfiirmProcessItvmEpaymentController {

    private final SwCkConfiirmProcessItvmEpaymentService swCkConfiirmProcessItvmEpaymentService;

    /**
     * 列表查询
     * @param
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/listSwCkConfiirmProcessItvmEpayment" )
    public R listSwCkConfiirmProcessItvmEpayment(String startDate,String endDate,String confirmStatus) {
        String ordflag = null;
        return R.ok(swCkConfiirmProcessItvmEpaymentService.listSwCkConfiirmProcessItvmEpayment(startDate,endDate,confirmStatus,ordflag));
    }

    /**
     * ITVM支付批量确认，注意：只填充状态是未确认的 
     * @param list
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "ITVM支付批量确认，注意：只填充状态是未确认的", notes = "ITVM支付批量确认，注意：只填充状态是未确认的")
    @SysLog("ITVM支付批量确认")
    @PostMapping({ "/saveBatchConfirm" })
    @PreAuthorize("@pms.hasPermission('sw_ck_confiirm_process_itvm_epayment_confirm')")
    public R saveBatchConfirm(@RequestBody List<SwCkConfiirmProcessItvmEpaymentNewDTO> list) throws Exception {

        List<SwCkConfiirmProcessItvmEpayment> listDb = new ArrayList<>();
        for(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment : list){
            SwCkConfiirmProcessItvmEpayment group1_title1 =  setObjProperties1_1(swCkConfiirmProcessItvmEpayment);
            SwCkConfiirmProcessItvmEpayment group1_title2 =  setObjProperties1_2(swCkConfiirmProcessItvmEpayment);
            SwCkConfiirmProcessItvmEpayment group1_title3 =  setObjProperties1_3(swCkConfiirmProcessItvmEpayment);
            SwCkConfiirmProcessItvmEpayment group2_title2 =  setObjProperties2_2(swCkConfiirmProcessItvmEpayment);
            SwCkConfiirmProcessItvmEpayment group2_title3 =  setObjProperties2_3(swCkConfiirmProcessItvmEpayment);
            //BeanUtils.copyProperties(swCkConfiirmProcessItvmEpayment,obj);
            listDb.add(group1_title1);
            listDb.add(group1_title2);
            listDb.add(group1_title3);
            listDb.add(group2_title2);
            listDb.add(group2_title3);
        }

        return R.ok(swCkConfiirmProcessItvmEpaymentService.saveBatch(listDb));
    }
    /**
     * ITVM支付批量删除确认，注意：只填充状态是已确认的
     * @param list
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "ITVM支付批量删除确认，注意：只填充状态是已确认的 ", notes = "ITVM支付批量删除确认，注意：只填充状态是已确认的 ")
    @SysLog("ITVM支付批量删除确认")
    @PostMapping({ "/delBatchConfirm" })
    public R delBatchConfirm(@RequestBody List<SwCkConfiirmProcessItvmEpaymentNewDTO> list) throws Exception {

        for(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment : list){
            LambdaQueryWrapper<SwCkConfiirmProcessItvmEpayment> queryWrapper = Wrappers.<SwCkConfiirmProcessItvmEpayment>lambdaQuery()
                    .eq(SwCkConfiirmProcessItvmEpayment::getTradeDate, swCkConfiirmProcessItvmEpayment.getTradeDate());
            swCkConfiirmProcessItvmEpaymentService.remove(queryWrapper);
        }
        return R.ok();
    }

    private SwCkConfiirmProcessItvmEpayment setObjProperties1_1(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment) {
        final SwCkConfiirmProcessItvmEpayment obj =  ObjectUtils.getDefaultObj(SwCkConfiirmProcessItvmEpayment.class);
        obj.setTradeDate(swCkConfiirmProcessItvmEpayment.getTradeDate());
        obj.setMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title1_money());
        obj.setServiceCharge(swCkConfiirmProcessItvmEpayment.getLineGroup1_title1_serviceCharge());
        obj.setBankMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title1_bankMoney());
        obj.setDiffMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title1_diffMoney());
        obj.setLineGroup("1");
        obj.setTitle("1");
        return obj;
    }
    private SwCkConfiirmProcessItvmEpayment setObjProperties1_2(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment) {
        final SwCkConfiirmProcessItvmEpayment obj =  ObjectUtils.getDefaultObj(SwCkConfiirmProcessItvmEpayment.class);
        obj.setTradeDate(swCkConfiirmProcessItvmEpayment.getTradeDate());
        obj.setMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title2_money());
        obj.setServiceCharge(swCkConfiirmProcessItvmEpayment.getLineGroup1_title2_serviceCharge());
        obj.setBankMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title2_bankMoney());
        obj.setDiffMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title2_diffMoney());
        obj.setLineGroup("1");
        obj.setTitle("2");
        return obj;
    }
    private SwCkConfiirmProcessItvmEpayment setObjProperties1_3(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment) {
        final SwCkConfiirmProcessItvmEpayment obj =  ObjectUtils.getDefaultObj(SwCkConfiirmProcessItvmEpayment.class);
        obj.setTradeDate(swCkConfiirmProcessItvmEpayment.getTradeDate());
        obj.setMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title3_money());
        obj.setServiceCharge(swCkConfiirmProcessItvmEpayment.getLineGroup1_title3_serviceCharge());
        obj.setBankMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title3_bankMoney());
        obj.setDiffMoney(swCkConfiirmProcessItvmEpayment.getLineGroup1_title3_diffMoney());
        obj.setLineGroup("1");
        obj.setTitle("3");
        return obj;
    }
    private SwCkConfiirmProcessItvmEpayment setObjProperties2_2(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment) {
        final SwCkConfiirmProcessItvmEpayment obj =  ObjectUtils.getDefaultObj(SwCkConfiirmProcessItvmEpayment.class);
        obj.setTradeDate(swCkConfiirmProcessItvmEpayment.getTradeDate());
        obj.setMoney(swCkConfiirmProcessItvmEpayment.getLineGroup2_title2_money());
        obj.setServiceCharge(swCkConfiirmProcessItvmEpayment.getLineGroup2_title2_serviceCharge());
        obj.setBankMoney(swCkConfiirmProcessItvmEpayment.getLineGroup2_title2_bankMoney());
        obj.setDiffMoney(swCkConfiirmProcessItvmEpayment.getLineGroup2_title2_diffMoney());
        obj.setLineGroup("2");
        obj.setTitle("2");
        return obj;
    }
    private SwCkConfiirmProcessItvmEpayment setObjProperties2_3(SwCkConfiirmProcessItvmEpaymentNewDTO swCkConfiirmProcessItvmEpayment) {
        final SwCkConfiirmProcessItvmEpayment obj =  ObjectUtils.getDefaultObj(SwCkConfiirmProcessItvmEpayment.class);
        obj.setTradeDate(swCkConfiirmProcessItvmEpayment.getTradeDate());
        obj.setMoney(swCkConfiirmProcessItvmEpayment.getLineGroup2_title3_money());
        obj.setServiceCharge(swCkConfiirmProcessItvmEpayment.getLineGroup2_title3_serviceCharge());
        obj.setBankMoney(swCkConfiirmProcessItvmEpayment.getLineGroup2_title3_bankMoney());
        obj.setDiffMoney(swCkConfiirmProcessItvmEpayment.getLineGroup2_title3_diffMoney());
        obj.setLineGroup("2");
        obj.setTitle("3");
        return obj;
    }

    /**
     * 导出
     * @param
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "ITVM支付导出", notes = "ITVM支付导出")
    @GetMapping({"/export"})
    @SysLog("ITVM支付导出")
    @PreAuthorize("@pms.hasPermission('sw_ck_confiirm_process_itvm_epayment_export')")
    public void export(String startDate,String endDate,String confirmStatus,HttpServletResponse response){
        String ordflag = "1";
        swCkConfiirmProcessItvmEpaymentService.exportExcel(startDate,endDate,confirmStatus,ordflag,response);
    }

}
